package study.intconsulting.client;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;

import study.intconsulting.services.RayService2;
import study.intconsulting.services.ServiceExecuter;
import study.intconsulting.vo.PcInfo;

public class NewStart {

	private final static String REQUEST_MESSAGE = "who";
	
	public static void main(String[] args) {
		System.out.println("#############################");
		System.out.println("- Service Start...");
		System.out.println("- Reqeust Message : " + REQUEST_MESSAGE);
		
		long sTime = System.currentTimeMillis();
		
		NewStart start = new NewStart();
		start.requestService(REQUEST_MESSAGE);
		
		long eTime = System.currentTimeMillis();

		System.out.println("- Service End...");
		System.out.println("-----------------------------");
		System.out.println("- 소요시간:" + (eTime - sTime));
		System.out.println("#############################");
	}
	
	private void requestService(String message) {
		PcInfo pi = new PcInfo();
		pi.setName(message);
		
		// annotation 사용
//		ApplicationContext context = new AnnotationConfigApplicationContext(ServiceFactory.class);
		
		// xml 사용
		ApplicationContext context = new GenericXmlApplicationContext("applicationContext.xml");
		ServiceExecuter service = context.getBean("rayService" , RayService2.class);
		
		try {
			pi = service.execute(pi);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		System.out.println("NewStart ip = " + pi.getIp());
		System.out.println("NewStart name = " + pi.getName());
		System.out.println("NewStart who = " + pi.getWho());
		
		
	}
	
}
